﻿Imports System.Activities
Imports System.Activities.Presentation.Metadata
Imports System.Drawing
Imports System.ComponentModel

Public Class RemoveHashtableValue
    Inherits CodeActivity
    Implements IRegisterMetadata

    Public Property HashArgument As InOutArgument(Of Hashtable)
    Public Property KeyName As InArgument(Of String)

    Public Sub New()
        Me.DisplayName = My.Resources.RemoveHashtableValueDisplayName
    End Sub

    Protected Overrides Sub Execute(context As System.Activities.CodeActivityContext)
        Dim ht = context.GetValue(Me.HashArgument)
        Dim key = context.GetValue(Me.KeyName)

        If Not ht.ContainsKey(key) Then Return
        ht.Remove(key)

        context.SetValue(Me.HashArgument, ht)
    End Sub


    Public Sub Register() Implements System.Activities.Presentation.Metadata.IRegisterMetadata.Register
        Dim build As New AttributeTableBuilder
        'RemoveHashtableValue Activity
        build.AddCustomAttributes(GetType(RemoveHashtableValue),
                                              New DesignerAttribute(GetType(RemovetHashtableValueDesigner)),
                                              New ToolboxBitmapAttribute(GetType(RemoveHashtableValue), "RemoveHashtableValue.png"))

        build.AddCustomAttributes(GetType(RemoveHashtableValue), "DisplayName",
                                      New CategoryAttribute(My.Resources.CategorySetting),
                                      New DisplayNameAttribute(My.Resources.DisplayNameDisplay))

        build.AddCustomAttributes(GetType(RemoveHashtableValue), "HashArgument",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New RequiredArgumentAttribute(),
                                      New DisplayNameAttribute(My.Resources.HashArgumentDisplay),
                                      New DescriptionAttribute(My.Resources.HashArgumentDescription))
        build.AddCustomAttributes(GetType(RemoveHashtableValue), "KeyName",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New RequiredArgumentAttribute(),
                                      New DisplayNameAttribute(My.Resources.KeyNameDisplay),
                                      New DescriptionAttribute(My.Resources.KeyNameDescription))

        MetadataStore.AddAttributeTable(build.CreateTable)
    End Sub

End Class
